package com.suse.warmstill.common.model;

//import io.swagger.annotations.ApiModel;
//import io.swagger.annotations.ApiModelProperty;

import com.suse.warmstill.common.enums.ResponseEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;


import java.io.Serializable;

/**
 * @author Jarno
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder

@ApiModel("返回模型")
public class CallResult<T> implements Serializable {

    @ApiModelProperty(name = "code", value = "返回状态值")
    private int code;

    @ApiModelProperty(name = "msg", value = "返回信息")
    private String message;

    @ApiModelProperty(name = "返回的数据", value = "携带参数")
    private T result;

    public static <T> CallResult<T> success() {
        return new CallResult<T>(ResponseEnum.DEFAULT_SUCCESS.getCode(), ResponseEnum.DEFAULT_SUCCESS.getMsg(), null);
    }

    public static <T> CallResult<T> success(T result) {
        return new CallResult<T>(ResponseEnum.DEFAULT_SUCCESS.getCode(), ResponseEnum.DEFAULT_SUCCESS.getMsg(), result);
    }

    public static <T> CallResult<T> success(int code, String message, T result) {
        return new CallResult<T>(code, message, result);
    }

    public static <T> CallResult<T> fail() {
        return new CallResult<T>(ResponseEnum.DEFAULT_SYS_ERROR.getCode(), ResponseEnum.DEFAULT_SYS_ERROR.getMsg(), null);
    }

    public static <T> CallResult<T> fail(T result) {
        return new CallResult<T>(ResponseEnum.DEFAULT_SYS_ERROR.getCode(), ResponseEnum.DEFAULT_SYS_ERROR.getMsg(), result);
    }

    public static <T> CallResult<T> fail(int code, String message) {
        return new CallResult<T>(code, message, null);
    }

    public static <T> CallResult<T> fail(String message, T result) {
        return new CallResult<T>(ResponseEnum.DEFAULT_SYS_ERROR.getCode(), message, result);
    }

    public static <T> CallResult<T> fail(int code, String message, T result) {
        return new CallResult<T>(code, message, result);
    }

    public boolean isSuccess() {
        return this.code == ResponseEnum.DEFAULT_SUCCESS.getCode();
    }

}
